package org.fhm.zdte.common.service.message;

import org.fhm.substrate.annotation.BeanEnable;
import org.fhm.substrate.annotation.Component;
import org.fhm.substrate.annotation.Setup;
import org.fhm.substrate.manager.Bootstrap;
import org.fhm.substrate.service.LoggerHandler;
import org.fhm.substrate.standard.ILogger;
import org.fhm.zdte.common.constant.protocol.ContentType;
import org.fhm.zdte.common.pojo.Request;
import org.fhm.zdte.common.standard.IJsonConvertor;

/**
 * TEXT sends message manager.
 *
 * @author 谭波
 * @since 2023/11/15
 */
@Component("TEXT")
public class TextSendMessageManager extends AbstractSendMessageManager {

    @Setup
    private IJsonConvertor iJsonConvertor;

    public TextSendMessageManager() {
        super(ContentType.TEXT);
    }

    @Override
    protected byte[] convert(Request request) {
        return iJsonConvertor.toJson(request).getBytes(Bootstrap.charset);
    }

    @BeanEnable
    private void beanEnable() {
        setLengthOfPacketWithContent();
        setResendPacketCount();
        ILogger logger = LoggerHandler.getLogger(TextSendMessageManager.class);
        logger.info("the configured number of resend packets is {}", resendPacketCount);
        setFirstSendPacketCount();
        logger.info("the configured number of first send packets is {}", firstSendPacketCount);
    }
}
